package collection;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class LinkedListTest {
    public static void main(String[] args){
        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");

        for(int i=0; i<list.size(); i++){
            System.out.println(list.get(i));
        }
        System.out.println("---------------------");
        for(String str:list){
            System.out.println(str);
        }
        System.out.println("----------LinkedList-----------");
        LinkedList<String> linkedList = new LinkedList<>();
        linkedList.add("a");
        linkedList.add("b");
        linkedList.add("c");

        for(String str:linkedList){
            System.out.println(str);
        }
        System.out.println("---------------------");
        String s = linkedList.getFirst();
        System.out.println(s);//a
        String s1 = linkedList.getLast();
        System.out.println(s1);//c
        System.out.println("---------------------");
        linkedList.removeFirst();
        linkedList.removeLast();
        for(String str:linkedList){//b
            System.out.println(str);
        }
        System.out.println("---------------------");
        linkedList.addFirst("a");
        linkedList.addLast("c");
        for(String str:linkedList){//abc
            System.out.println(str);
        }
        System.out.println("---------------------");
        String s2 = linkedList.peek();
        System.out.println(s2);//a
        String pop = linkedList.pop();
        System.out.println(pop);//a
        System.out.println("---------------------");
        linkedList.push("j");
        for(String str:linkedList){
            System.out.println(str);
        }


    }
}
